package airplane.obj;

import airplane.utils.GameUtils;
import airplane.war.GameWin;

import java.awt.*;

public class BoosObj extends GameObj {

    // 血量
    int bloodVolume = 100;

    public BoosObj(Image imag, int x, int y, int width, int height, int speed, GameWin gameWin) {
        super(imag, x, y, width, height, speed, gameWin);
    }

    public BoosObj(Image imag, int x, int y, int speed, GameWin gameWin) {
        super(imag, x, y, speed, gameWin);
    }


    @Override
    public void paintSelf(Graphics graphics) {
        super.paintSelf(graphics);
        if (x > 520 || x < -30){
            speed = -speed;
        }
        x +=speed;

        if (GameWin.score > 10 && bloodVolume > 0){
            for (ShellObj shellObj : GameUtils.shellObjList) {
                if (this.getRec().intersects(shellObj.getRec())) {
                    GameWin.score += 10;
                    shellObj.setX(-100);
                    bloodVolume--;
                    if (bloodVolume <= 0) {
                        speed = 0;
                        GameWin.state = 4;
                        gameWin.repaint = 0;
                    }
                    /**
                     * 转变速度
                     */
                    if (bloodVolume < 50 && speed == 3){
                        speed = 6;
                    }
                }
            }
        }
    }

}
